﻿using System;
using System.Reflection;
using System.Collections.Generic;
using System.Text;

namespace SchEdu.Framework.DataModel
{
    public class AboutInfo
    {
        public AboutInfo()
        {
            title = AssemblyTitle;
            version = AssemblyVersion;
            description = AssemblyDescription;
            product = AssemblyProduct;
            copyright = AssemblyCopyright;
            company = AssemblyCompany;
        }

        public AboutInfo(SchEduDataSet.PerformanceRow performance)
        {
            title = performance.Title;
            version = performance.Version;
            description = performance.Description;
            product = performance.Product;
            copyright = performance.Copyright;
            company = performance.Company;
            guid = performance.ObjectiveGuid;
        }

        #region Properties
        string title;

        public string Title
        {
            get { return title; }
            set { title = value; }
        }

        string version;

        public string Version
        {
            get { return version; }
            set { version = value; }
        }

        string description;

        public string Description
        {
            get { return description; }
            set { description = value; }
        }

        string product;

        public string Product
        {
            get { return product; }
            set { product = value; }
        }

        string copyright;

        public string Copyright
        {
            get { return copyright; }
            set { copyright = value; }
        }

        string company;

        public string Company
        {
            get { return company; }
            set { company = value; }
        }

        System.Guid guid;
        public System.Guid Guid
        {
            get { return guid; }
            set { guid = value; }
        }

        #endregion

        #region Assembly Attribute Accessors

        private string AssemblyTitle
        {
            get
            {
                object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
                if (attributes.Length > 0)
                {
                    AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)attributes[0];
                    if (titleAttribute.Title != "")
                    {
                        return titleAttribute.Title;
                    }
                }
                return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase);
            }
        }

        private string AssemblyVersion
        {
            get
            {
                return Assembly.GetExecutingAssembly().GetName().Version.ToString();
            }
        }

        private string AssemblyDescription
        {
            get
            {
                object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false);
                if (attributes.Length == 0)
                {
                    return "";
                }
                return ((AssemblyDescriptionAttribute)attributes[0]).Description;
            }
        }

        private string AssemblyProduct
        {
            get
            {
                object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute), false);
                if (attributes.Length == 0)
                {
                    return "";
                }
                return ((AssemblyProductAttribute)attributes[0]).Product;
            }
        }

        private string AssemblyCopyright
        {
            get
            {
                object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
                if (attributes.Length == 0)
                {
                    return "";
                }
                return ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
            }
        }

        private string AssemblyCompany
        {
            get
            {
                object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false);
                if (attributes.Length == 0)
                {
                    return "";
                }
                return ((AssemblyCompanyAttribute)attributes[0]).Company;
            }
        }
        #endregion

    }
}
